package estimators.numberoOfDocuments;

import java.util.ArrayList;

import distributedRE.model.QueryDatabase;

public abstract class NumberOfDocumentCalculator implements DocumentEstimator{

	public static final int MUST_TERM = 1;
	public static final int MUST_NOT_TERM = -1;
	public static final int SHOULD = 0;
	
	public double estimateDocumentsRetrieved(QueryDatabase qdb){
		
		//we should remove the frequency of the already processed documents.
		
		ArrayList<String> must_terms = qdb.getQuery().getMustWords();
		
		double added = 0;
		
		for (String must_term : must_terms) {
			
			added += Math.log(getMustProbability(must_term, qdb));
			
		}
		
		ArrayList<String> must_not_terms = qdb.getQuery().getMustNotWords();
		
		for (String must_not_term : must_not_terms) {
			
			added += Math.log(getMustNotProbability(must_not_term, qdb));
			
		}
		
		return Math.pow(Math.E, added + Math.log(qdb.getNumberOfDocuments()));
		
	}
	
	protected abstract double getMustProbability(String term, QueryDatabase qdb);
	
	protected abstract double getMustNotProbability(String term, QueryDatabase qdb);

}
